unit ServerController;

interface

uses
  SysUtils, Classes, IWServerControllerBase, IWBaseForm, HTTPApp,
  // For OnNewSession Event
  IWUserS, IWApplication, IWAppForm,SyncObjs;

type
  TIWServerController = class(TIWServerControllerBase)
    
    procedure IWServerControllerBaseNewSession(ASession: TIWApplication;
      var VMainForm: TIWBaseForm);
    procedure IWServerControllerBaseCreate(Sender: TObject);
  (*  procedure CreateUniqueUserFileNamePair( iPrefix, iExt : string;
                        out iPhysicalFileName : string;
                        out iURLFileName      : string );  *)
  private
  public
  end;


  function UserSession: TIWUserSession;
  function IWServerController: TIWServerController;
var
mFNCS : TCriticalSection;

implementation
{$R *.dfm}

uses
  IWInit, IWGlobal;

function IWServerController: TIWServerController;
begin
  Result := TIWServerController(GServerController);
end;

function UserSession: TIWUserSession;
begin
  Result := TIWUserSession(WebApplication.Data);
end;



procedure TIWServerController.IWServerControllerBaseNewSession(
  ASession: TIWApplication; var VMainForm: TIWBaseForm);
begin
  ASession.Data := TIWUserSession.Create(nil);
end;
(*
procedure TIWServerController.CreateUniqueUserFileNamePair(
                            iPrefix, iExt : string;
                        out iPhysicalFileName : string;
                        out iURLFileName      : string );
var aFileName : string;
begin
  mFNCS.Acquire;  // TCriticalSection owned by the server controller
  try
    try
      iPhysicalFileName := CreateUniqueFileName(
                  WebApplication.UserCacheDir +  iPrefix, iExt );
      aFileName     := JustFileNameW( iPhysicalFileName );
      iURLFileName  := WebApplication.UserCacheURL + aFileName;

    except on e : exception do
     raise EcmServerController.create(
                    'CreateUniqueUserFileNamePair', e );
    end;
  finally
    mFNCS.Release;
  end;
end;
*)
procedure TIWServerController.IWServerControllerBaseCreate(
  Sender: TObject);
begin
   IWServerController.CacheDir := ExtractFilePath(paramstr(0))+'cache';
end;

initialization
  TIWServerController.SetServerControllerClass;

end.

 